<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Setting extends MX_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->library('Admin_Layout');
    }
    
    public function index()
    {
        $this->mycommon->authAdmin();
        $data = array();
        $data['error'] = '';
        $this->load->model('category/category_model');
        $this->load->model('setting/setting_model');
        if ($this->input->post()) {
            $lstMenubar = $this->input->post('lstMenubar');
            $lstBoxHome = $this->input->post('lstBoxHome');
            if ($this->setting_model->setOption('lstMenubar', $lstMenubar)) {
                if ($this->setting_model->setOption('lstBoxHome', $lstBoxHome)) {
                    echo "Cập nhật thành công!";
                    die;
                }
                echo "Có lỗi xảy ra, vui lòng thử lại";
                die;
            }
            echo "Có lỗi xảy ra, vui lòng thử lại";
            die;
        }
        $lstMenubar = $this->setting_model->getOptionByName('lstMenubar');
        $lstBoxHome = $this->setting_model->getOptionByName('lstBoxHome');
        $arrMenubar = ($lstMenubar) ? explode(',', $lstMenubar['value']) : '';
        $arrBoxHome = ($lstBoxHome) ? explode(',', $lstBoxHome['value']) : '';
        $data['lstMenubar'] = '';
        $data['lstBoxHome'] = '';
        if ($arrMenubar != '') {
            foreach ($arrMenubar as $k=>$v) {
                $data['lstMenubar'][$k]['info'] = $this->category_model->getCategoryById($v);
            }
        }
        if ($arrBoxHome != '') {
            foreach ($arrBoxHome as $_k=>$_v) {
                $data['lstBoxHome'][$_k]['info'] = $this->category_model->getCategoryById($_v);
            }
        }
        $data['category'] = $this->category_model->getParentCategory();
        $this->admin_layout->view('setting/setting_view', $data);
    }

}

?>
